package com.itbupt.test.trigger;

import com.alibaba.fastjson.JSON;
import com.itbupt.trigger.api.IRaffleActivityService;
import com.itbupt.trigger.api.dto.ActivityDrawRequestDTO;
import com.itbupt.trigger.api.dto.ActivityDrawResponseDTO;
import com.itbupt.trigger.api.dto.SkuProductResponseDTO;
import com.itbupt.trigger.api.dto.SkuProductShopCartRequestDTO;
import com.itbupt.trigger.api.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author dingchang
 * @Date 2025/4/9 1:04
 * @Description: 抽奖活动服务测试
 */

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class RaffleActivityControllerTest1 {


    @Resource
    private IRaffleActivityService raffleActivityService;
    @Resource
    private CuratorFramework curatorFramework;

    @Test
    public void test_armory() {
        Response<Boolean> response = raffleActivityService.armory(100301L);
        log.info("测试结果：{}", JSON.toJSONString(response));
    }

    @Test
    public void test_calendarSignRebate(){
        //要先在redis里面预热
        Response<Boolean> response = raffleActivityService.calendarSignRebate("user003");
        log.info("测试结果：{}", JSON.toJSONString(response));
    }

    @Test
    public void test_isCalendarSignRebate(){
        Response<Boolean> response = raffleActivityService.isCalendarSignRebate("user003");
        log.info("测试结果：{}", JSON.toJSONString(response));
    }


    @Test
    public void test_blacklist_draw() throws InterruptedException {
        ActivityDrawRequestDTO request = new ActivityDrawRequestDTO();
        request.setActivityId(100301L);
        request.setUserId("user003");

        Response<ActivityDrawResponseDTO> response = raffleActivityService.draw(request);

        log.info("请求参数：{}", JSON.toJSONString(request));
        log.info("测试结果：{}", JSON.toJSONString(response));

        // new CountDownLatch(1).await();

    }

    // 查询sku商品集合
    @Test
    public void test_querySkuProductListByActivityId() {
        Long request = 100301L;
        Response<List<SkuProductResponseDTO>> response = raffleActivityService.querySkuProductListByActivityId(request);

        log.info("请求参数：{}", JSON.toJSONString(request));
        log.info("测试结果：{}", JSON.toJSONString(response));
    }

    // 查询用户积分值
    @Test
    public void test_queryUserCreditAccount() {
        String request = "dingchang";
        Response<BigDecimal> response = raffleActivityService.queryUserCreditAccount(request);
        log.info("请求参数：{}", JSON.toJSONString(request));
        log.info("测试结果：{}", JSON.toJSONString(response));
    }

    // 积分支付兑换商品
    @Test
    public void test_creditPayExchangeSku() throws InterruptedException {
        SkuProductShopCartRequestDTO request = new SkuProductShopCartRequestDTO();
        request.setUserId("dingchang");
        request.setSku(9011L);
        Response<Boolean> response = raffleActivityService.creditPayExchangeSku(request);
        log.info("请求参数：{}", JSON.toJSONString(request));
        log.info("测试结果：{}", JSON.toJSONString(response));

        new CountDownLatch(1).await();
    }

    @Test
    public void test_set_dcc_value() throws Exception {
        curatorFramework.setData().forPath("/big-market-dcc/config/degradeSwitch", "close".getBytes(StandardCharsets.UTF_8));
    }


}
